<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<head>
    <title>密码找回</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据 - AdminLTE2定制版 | verify2 </title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="${path}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${path}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${path}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${path}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${path}/plugins/iCheck/square/blue.css">
</head>
<script>
    window.onload = function () {
        if (window.parent.window != window) {
            window.top.location = "/verify.jsp";
        }
    }
</script>
<body class="hold-transition login-page">

<div class="login-box">
    <div class="login-logo">
        <a href="all-admin-index.html">SaaS外贸出口云平台</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg" style="font-size:25px;">密码找回</p>
        <form action="/system/user/verify.do" method="post">
            <div class="form-group has-feedback">
                <input type="tel" id="telephone" class="form-control" placeholder="请输入手机号" value="${requestScope.get("telephone")}">
                <%--<span class="glyphicon glyphicon-envelope form-control-feedback"></span>--%>
            </div>
            <div class="form-group has-feedback">
                <input type="text" id="smsCode" name="password" class="form-control" placeholder="验证码">
                <%--<span class="glyphicon glyphicon-lock form-control-feedback"></span>--%>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label id="errorMsg" class="" style="color: #c12e2a">${requestScope.get("resultInfo").errorMsg}</label>
                    </div>
                </div>
                <div class="col-xs-4">
                    <button type="button" id="sendSmsCode" class="btn btn-primary btn-block btn-flat" style="width:85px;height:35px;font-size:10px">获取验证码</button>
                </div>
            </div>
        </form>

        <div class="social-auth-links text-center">
            <a href="javascript:void(0)" id = "verifyBtn" class="btn btn-primary btn-block btn-flat">确定</a>
        </div>

    </div>
</div>


<script src="${path}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${path}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${path}/plugins/iCheck/icheck.min.js"></script>
<script>
    $(function(){
        var countdown = 10;
        var clearIntervalCode = 0;
        //手机号正则表达式
        var pattern = /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^(([0\+]\d{2,3})?(0\d{2,3}))(\d{7,8})((\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        $("#sendSmsCode").click(function(){
            $("#errorMsg").html("");
            //alert("获取验证码点击测试");
            //获取当前用户 的手机号
            let telephoneval = $("#telephone").val();
            if (telephoneval == ''){
                //alert("请输入手机号");
                $("#errorMsg").html("请输入手机号");
                return false;
            }else if (!pattern.test($("#telephone").val())){
                //alert("请输入正确的手机号");
                $("#errorMsg").html("请输入正确的手机号");
                return false;
            }
            //3.发送ajax
            $.ajax({
                url:"/system/user/sendSmsCode.do",
                data:"telephone="+telephoneval,
                type:"post",
                success:function(resultInfo){
                    //alert(resultInfo.successMsg);
                },
                error: function(resultInfo){
                    //alert(resultInfo.errorMsg);
                }
            })
            var obj = $("#sendSmsCode");

            clearIntervalCode = window.setInterval(function(){
                settime(obj);
            },1000);

        })

        //发送验证码倒计时
        function settime(obj){
            if (countdown == 0){
                obj.attr('disabled',false);
                obj.html("获取验证码");
                countdown = 10;
                window.clearInterval(clearIntervalCode);
                return;
            }else{
                obj.attr('disabled',true);
                obj.html("重新发送(" + countdown + ")");
                countdown --;
            }
        }

        //验证验证码是否正确
        //1.绑定点击事件
        $("#verifyBtn").click(function(){
            $("#errorMsg").html("");
            //点击事件测试
            let telephoneVal = $("#telephone").val();
            let smsCodeVal = $("#smsCode").val();

            //判断手机号是否输入正确
            if (telephoneVal == ''){
                //alert("请输入手机号");
                $("#errorMsg").html("请输入手机号");
                return false;
            }else if (!pattern.test($("#telephone").val())){
                //alert("请输入正确的手机号");
                $("#errorMsg").html("请输入正确的手机号");
                return false;
            }
            //判断验证码是否输入正确
            if (smsCodeVal == ''){
                //alert("请输入验证码");
                $("#errorMsg").html("请输入验证码");
                return false;
            }else if (smsCodeVal.length != 6){
                //alert("验证码格式有误");
                $("#errorMsg").html("请输入验证码");
                return false;
            }

            location.href="/system/user/verify.do?telephone=" + telephoneVal + "&smsCode=" + smsCodeVal;
        })
    })
    //*******************************************************************************************//

    //获取验证码
    //1.绑定点击事件
    /*$("#sendSmsCode").click(function(){
        alert("获取验证码点击测试");
        //手机号正则表达式
        let pattern = /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^(([0\+]\d{2,3})?(0\d{2,3}))(\d{7,8})((\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        //2.获取当前用户 的手机号
        let telephoneval = $("#telephone").val();
        if (telephoneval == ''){
            alert("请输入手机号");
            return false;
        }else if (!pattern.test($("#telephone").val())){
            alert("请输入正确的手机号");
            return false;
        }
        //3.发送ajax
        $.ajax({
            url:"/system/user/sendSmsCode.do",
            data:"telephone="+telephoneval,
            type:"post",
            success:function(resultInfo){
                alert(resultInfo.successMsg);
            },
            error: function(resultInfo){
                alert(resultInfo.errorMsg);
            }
        })

    })*/


    /* var vercode	 = 0;
     var time = 60;
     var flag = true;   //设置点击标记，防止60内再次点击生效
     //发送验证码
     $('#sendSmsCode').click(function(){

         //手机号正则表达式
         let pattern = /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^(([0\+]\d{2,3})?(0\d{2,3}))(\d{7,8})((\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
         //2.获取当前用户 的手机号
         let telephoneval = $("#telephone").val();
         if (telephoneval == ''){
             alert("请输入手机号");
             return false;
         }else if (!pattern.test($("#telephone").val())){
             alert("请输入正确的手机号");
             return false;
         }

         $(this).attr("disabled",true);
         var telephoneVal = $('#telephone').val();
         if(flag){
             var timer = setInterval(function () {
                 if(time == 60 && flag){
                     flag = false;
                     alert("即将跳转");
                     $.ajax({
                         url:"/system/user/sendSmsCode.do",
                         data:"telephone="+telephoneVal,
                         type:"post",
                         success : function(resultInfo) {
                             if(resultInfo.flag){
                                 vercode = resultInfo.successMsg;
                                 $("#sendSmsCode").html("已发送");
                             }else {
                                 alert(resultInfo.errorMsg);
                                 flag = true;
                                 time = 60;
                                 clearInterval(timer);
                             }
                         }
                     });
                 }else if(time == 0){
                     $("#sendSmsCode").removeAttr("disabled");
                     $("#sendSmsCode").html("获取验证码");
                     clearInterval(timer);
                     time = 60;
                     flag = true;
                 }else {
                     $("#sendSmsCode").html(time + "s重新发送");
                     time--;
                 }
             },1000);
         }
     });*/
</script>
</body>
</html>
